<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <!-- @开始事件绑定 -->
        <h2>{{title}}</h2>
        <input type="text" v-model="title" @keydown.enter="addTodos">
        <ul>
            <!-- {todo.map} -->
            <!-- vue 又提供了一个组件给我们 for key in json -->
            <li v-for="todo in todos">
                <input type="checkbox" v-model="todo.done">
                <span :class="{done:todo.done}">{{todo.title}}</span>
            </li>
        </ul>
        <div>
            {{todos.filter(v =>!v.done).length}}/{{todos.length}}
            <hr>
            <!-- 计算属性 -->
            {{active}}/{{all}}
        
        </div>
    </div>
    <script src="https://unpkg.com/vue@next"></script>
    <script>
        const App = {
            data() {
                return {
                    title:" ",
                    todos:[
                        {title:"吃饭",done:false},
                        {title:"睡觉",done:true}
                    ]
                }
            },
            methods:{
                addTodos() {
                    // this 直接找到状态 this.state.todos
                    // 直接修改状态 就会触发mvvm
                    this.todos.push({
                        title:this.title,
                        done:false
                    })
                    this.title=" "
                }
            },
            computed: {
                    active() {
                        // react usefffect(,[todo]) + 申明 active状态
                        return this.todos.filter(v =>!v.done).length
                    },
                    all() {
                        return this.todos.length
                    }
                }
        }
        Vue.createApp(App).mount('#app')                                                                         
    </script>
    <style>
        .done {
            color:gray;
            text-decoration: line-through;
        }
    </style>
</body>
   
</html>